// -------------------------------------------------
// BlinKit - BlinKit Library
// -------------------------------------------------
//   File Name: microtask.cpp
// Description: Microtask Class
//      Author: Ziming Li
//     Created: 2022-04-24
// -------------------------------------------------
// Copyright (C) 2022 MingYang Software Technology.
// -------------------------------------------------

#include "./microtask.h"

#include "blinkit/blink/renderer/bindings/core/qjs/qjs.h"

namespace BlinKit {

void Microtask::PerformCheckpoint(JSRuntime *rt)
{
    if (!JS_IsJobPending(rt))
        return;

    int err;
    do {
        JSContext *ctx;
        err = JS_ExecutePendingJob(rt, &ctx);
        if (err < 0)
        {
            qjs::DumpException(ctx);
            ASSERT(err >= 0);
        }
    } while (err != 0);
}

} // namespace BlinKit
